package com.type;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.postgresql.geometric.PGpoint;
import org.springframework.data.geo.Point;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * <p>
 *
 * </p>
 *
 * @author zhangqing
 * @since 2021/2/25
 */
@MappedJdbcTypes(JdbcType.UNDEFINED)
@MappedTypes(Point.class)
public class PointType extends BaseTypeHandler<Point> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Point parameter, JdbcType jdbcType) throws SQLException {
        ps.setObject(i,parameter.toString());
    }

    @Override
    public Point getNullableResult(ResultSet rs, String columnName) throws SQLException {

        return null;
    }

    @Override
    public Point getNullableResult(ResultSet rs, int columnIndex) throws SQLException {

        return rs.getObject(columnIndex,Point.class);
    }

    @Override
    public Point getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return cs.getObject(columnIndex,Point.class);
    }
}
